package backgammon;

/**
 *
 * @author Jacob Kwitkoski
 * @version 1.0
 */
public class Move {
    private int fromPosition;

    private int toPosition;

    private boolean usesDie1;

    private boolean usesDie2;

    private String moveType;

    public static final String ADD_MOVE;

    public static final String BEAR_OFF;

    public static final String BLOT_MOVE;

    public static final String FROM_BAR;

    public static final String ORIGINAL_POSITION;

    static {
        ADD_MOVE = "add";
        BEAR_OFF = "bear off";
        BLOT_MOVE = "blot";
        FROM_BAR = "from bar";
        ORIGINAL_POSITION = "originalPosition";
    }

    /**
     *
     * @param newToPosition
     * @param newMoveType
     * @param usesDie 1 if uses die1, 2 if uses die2, 3 if uses both dice
     */
    public Move(final int    newFromPosition,
                final int    newToPosition,
                final String newMoveType,
                final int    usesDie) {
        fromPosition = newFromPosition;
        toPosition = newToPosition;
        moveType = newMoveType;
        if (fromPosition == toPosition) {
            usesDie1 = false;
            usesDie2 = false;
        } else {
            setDiceUsed(usesDie);
        }
    }

    public Move(final int    newPosition,
                final String newMoveType) {
        fromPosition = newPosition;
        toPosition = newPosition;
        moveType = newMoveType;
        usesDie1 = false;
        usesDie2 = false;
    }

    private void setDiceUsed(final int dice) {
        switch(dice) {
            case(1):
                usesDie1 = true;
                usesDie2 = false;
                break;
            case(2):
                usesDie1 = false;
                usesDie2 = true;
                break;
            case(3):
                usesDie1 = true;
                usesDie2 = true;
                break;
            default:
                usesDie1 = false;
                usesDie2 = false;
                break;
        }
    }

    public final String getMoveType() {
        return moveType;
    }

    public final int getFromPosition() {
        return fromPosition;
    }

    public final int getToPosition() {
        return toPosition;
    }

    public final boolean usesDie1() {
        return usesDie1;
    }

    public final boolean usesDie2() {
        return usesDie2;
    }


    @Override
    public final String toString() {
        StringBuilder builder = new StringBuilder();
        builder.append("\nTo position: " + toPosition);
        builder.append("\tMove type: " + moveType);
        builder.append("\tusesDie1: " + usesDie1);
        builder.append("\tusesDie2: " + usesDie2);
        return builder.toString();
    }
}
